//
//  AddNormalActionViewController.m
//  MarryAid
//
//  Created by Eric on 13-1-7.
//  Copyright (c) 2013年 marry aid. All rights reserved.
//

#import "AddNormalActionViewController.h"

#define addActionLeftWidth          20
#define addActionTopWidth           20
#define addActionNormalMidHeight    10
#define midxWidth   5
#define midyWidth   5

@interface AddNormalActionViewController ()

@end

@implementation AddNormalActionViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.title = @"添加事件";
    self.view.backgroundColor = [UIColor grayColor];
    
    [self initActionView];
    [self initActionTime];
    [self initReminderTime];
    [self initPlaceWidget];
    [self initCostWidget];
    [self initRemindPeopleWidget];
    [self initDoneButton];
}

#pragma mark -initActionTime

-(void)initActionView
{
    contentView = [[UITextView alloc] init];
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.delegate = self;
    contentView.frame = CGRectMake(addActionLeftWidth, addActionTopWidth, 320-addActionLeftWidth*2, 100);
    [self.view addSubview:contentView];
}

-(void)initActionTime
{
    //时间
    timeLabel = [[UILabel alloc] init];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.text = @"时间";
    timeLabel.frame = CGRectMake(addActionLeftWidth, contentView.frame.origin.y+contentView.frame.size.height+addActionNormalMidHeight, 40, 17);
    [self.view addSubview:timeLabel];
    
    timeButton = [[UIButton alloc]initWithFrame:CGRectMake(timeLabel.frame.origin.x+timeLabel.frame.size.width+midxWidth, timeLabel.frame.origin.y, 100,20)];
    //    [timeButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Login_loginbtn" ofType:@"png"]] forState:UIControlStateNormal];
    //todo
    [timeButton setTitle:@"2012-11-19" forState:UIControlStateNormal];
    [timeButton addTarget:self action:@selector(setActionTime) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:timeButton];
    
    //    UISwitch    *friendSwitch = [[[UISwitch alloc] init] autorelease];
    //    [friendSwitch addTarget:self action:@selector(meetAction:) forControlEvents:UIControlEventValueChanged];
    //    [friendSwitch setOn:app.currentUser.isRemindMeet];
    //    friendSwitch.frame = CGRectMake(RemindSegLeftWidth, RemindTopWidth-5, friendSwitch.frame.size.width, friendSwitch.frame.size.height);
}

-(void)initReminderTime
{
    //时间
    remindTimeLabel = [[UILabel alloc] init];
    remindTimeLabel.backgroundColor = [UIColor clearColor];
    remindTimeLabel.text = @"提醒时间";
    remindTimeLabel.frame = CGRectMake(addActionLeftWidth, timeLabel.frame.origin.y+timeLabel.frame.size.height+addActionNormalMidHeight, 100, 17);
    [self.view addSubview:remindTimeLabel];
    
    remindTimeButton = [[UIButton alloc]initWithFrame:CGRectMake(remindTimeLabel.frame.origin.x+remindTimeLabel.frame.size.width+midxWidth, remindTimeLabel.frame.origin.y, 100,20)];
    //    [remindTimeButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Login_loginbtn" ofType:@"png"]] forState:UIControlStateNormal];
    //todo
    [remindTimeButton setTitle:@"30分钟" forState:UIControlStateNormal];
    [remindTimeButton addTarget:self action:@selector(setReminderTime) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:remindTimeButton];
    
    //    UISwitch    *friendSwitch = [[[UISwitch alloc] init] autorelease];
    //    [friendSwitch addTarget:self action:@selector(meetAction:) forControlEvents:UIControlEventValueChanged];
    //    [friendSwitch setOn:app.currentUser.isRemindMeet];
    //    friendSwitch.frame = CGRectMake(RemindSegLeftWidth, RemindTopWidth-5, friendSwitch.frame.size.width, friendSwitch.frame.size.height);

}

-(void)initPlaceWidget
{
    placeLabel = [[UILabel alloc] init];
    placeLabel.backgroundColor = [UIColor clearColor];
    placeLabel.text = @"地点";
    placeLabel.frame = CGRectMake(addActionLeftWidth, remindTimeLabel.frame.origin.y+remindTimeLabel.frame.size.height+addActionNormalMidHeight, 40, 17);
    [self.view addSubview:placeLabel];
    
    placeField = [[UITextField alloc] init];
    placeField.backgroundColor = [UIColor whiteColor];
    placeField.frame = CGRectMake(placeLabel.frame.origin.x+placeLabel.frame.size.width+midxWidth, placeLabel.frame.origin.y, 200, 20);
    [self.view addSubview:placeField];
}

-(void)initCostWidget
{
    costLabel = [[UILabel alloc] init];
    costLabel.backgroundColor = [UIColor clearColor];
    costLabel.text = @"花费";
    costLabel.frame = CGRectMake(addActionLeftWidth, placeLabel.frame.origin.y+placeLabel.frame.size.height+addActionNormalMidHeight, 40, 17);
    [self.view addSubview:costLabel];
    
    costField = [[UITextField alloc] init];
    costField.backgroundColor = [UIColor whiteColor];
    costField.frame = CGRectMake(costLabel.frame.origin.x+costLabel.frame.size.width+midxWidth, placeLabel.frame.origin.y, 150, 20);
    [self.view addSubview:costField];
    
    costUnit = [[UILabel alloc] init];
    costUnit.backgroundColor = [UIColor clearColor];
    costUnit.text = @"元";
    costUnit.frame = CGRectMake(costField.frame.origin.x+costField.frame.size.width+midxWidth, costField.frame.origin.y, 20, 17);
    [self.view addSubview:costUnit];
}

-(void)initRemindPeopleWidget
{
    remindPeopleLabel = [[UILabel alloc] init];
    remindPeopleLabel.backgroundColor = [UIColor clearColor];
    //todo
    remindPeopleLabel.text = @"督促新郎办理";
    remindPeopleLabel.frame = CGRectMake(addActionLeftWidth, costLabel.frame.origin.y+costLabel.frame.size.height+addActionNormalMidHeight, 130, 17);
    [self.view addSubview:remindPeopleLabel];
    
    remindButton = [[UIButton alloc]initWithFrame:CGRectMake(remindPeopleLabel.frame.origin.x+remindPeopleLabel.frame.size.width+midxWidth, remindPeopleLabel.frame.origin.y, 100,20)];
    //    [remindTimeButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Login_loginbtn" ofType:@"png"]] forState:UIControlStateNormal];
    //todo
    [remindButton setTitle:@"提醒他" forState:UIControlStateNormal];
    [remindButton addTarget:self action:@selector(remindPeopleAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:remindButton];
}

-(void)initDoneButton
{
    okButton = [[UIButton alloc]initWithFrame:CGRectMake(50, remindPeopleLabel.frame.origin.y+remindPeopleLabel.frame.size.height+addActionNormalMidHeight, 320-2*50,20)];
    //    [remindTimeButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Login_loginbtn" ofType:@"png"]] forState:UIControlStateNormal];
    //todo
    [okButton setTitle:@"确定" forState:UIControlStateNormal];
    [okButton addTarget:self action:@selector(remindPeopleAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:okButton];
}

#pragma mark -Action

-(void)setActionTime
{
    NSLog(@"setActionTime");
}

-(void)setReminderTime
{
    NSLog(@"setReminderTime");
}

-(void)remindPeopleAction
{
    NSLog(@"remindPeopleAction");
}

#pragma mark -
#pragma mark UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"] && range.length == 0)
	{
        //        [self doCheckIn:self];
        [contentView resignFirstResponder];
//        scrollView.contentSize = CGSizeMake(app.scWidth, app.scHeight);
	}
    
//	if (checkLoading.loadingFlag)
//	{
//		return NO;
//	}
//	if (range.location>=140 && range.length==0)
//	{
//		return NO;
//	}
	
	return YES;
}

- (void)textViewDidChange:(UITextView *)textView
{

}

- (void)textViewDidEndEditing:(UITextView *)textView
{

}

#pragma mark -UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"textFieldDidEndEditing...");
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    //    switch (textField.tag)
    //    {
    //    case 1:
    //        {
    //            self.addName = textField.text;
    //        }
    //        break;
    //    case 2:
    //        {
    //            self.addAddress = textField.text;
    //        }
    //        break;
    //    default:
    //        break;
    //    }
    //    NSLog(@"+++ addname is %@,address is %@",addName,addAddress);
    return YES;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    //    switch (textField.tag)
    //    {
    //        case 1:
    //        {
    //            self.addName = textField.text;
    //        }
    //            break;
    //        case 2:
    //        {
    //            self.addAddress = textField.text;
    //        }
    //            break;
    //        default:
    //            break;
    //    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    //    switch (textField.tag)
    //    {
    //        case 1:
    //        {
    //            self.addName = textField.text;
    //        }
    //            break;
    //        case 2:
    //        {
    //            self.addAddress = textField.text;
    //        }
    //            break;
    //        default:
    //            break;
    //    }
    NSLog(@"textFieldShouldReturn");
    return YES;
}

@end
